/*
 * @Descripttion: 返回一个匹配器（match addRouters）
 * @version: 1.0
 * @Author: 张泽涛
 * @LastEditors: 张泽涛
 * @LastEditTime: 2021-02-23 23:49:03
 */
import createRouteMap from './create-route-map'
import createRoute from './utils/route'

export default function createMatcher (routes) {
  const { pathList, pathMap } = createRouteMap(routes)

  function match (path) {
    const record = pathMap[path]
    if (record) {
      return createRoute(record, path)
    }
    return createRoute(null, path)
  }
  function addRouters (routes) {
    createRouteMap(routes, pathList, pathMap)
  }

  return { match, addRouters }
}
